<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
namespace Admin\Controller;

use User\Api\UserApi as UserApi;
use Think\Model;
/**
 * 后台首页控制器
 *
 * @author 麦当苗儿 <zuojiazi@vip.qq.com>
 */
class PrizeController extends AdminController {

	/**
	 * 帐户流水记录
	 *
	 * @author 麦当苗儿 <zuojiazi@vip.qq.com>
	 */
	public function index() {

        /*if(isset($_GET['periods'])){
            $where['periods']=I('get.periods','','intval');
            $this->assign('periods',I('get.periods'));
        }
        if(isset($_GET['time'])){
            $where['time']=I('get.time','','intval');
            $this->assign('time',I('get.time'));
        }
        $this->meta_title = '猜涨跌活动列表';
       // $total        =  D('rose_activity')->where($where)->count();
        $total=D('rose_activity')->where($where)->order('periods asc,id desc')->count('DISTINCT periods');
        $listRows = C('LIST_ROWS') > 0 ? C('LIST_ROWS') : 10;
        $page = new \Think\Page($total, $listRows, $REQUEST);
        $limit=$page->firstRow.','.$page->listRows;
        $list=D('rose_activity')->field('id,periods_start_time,periods_end_time, periods')->where($where)->order('periods asc,id desc')->limit($limit)->select();
        if($total>$listRows){
            $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
        }
        $p =$page->show();
        $this->assign('_page', $p? $p: '');
        $this->assign('_total',$total);
        $this->list=$list;
        dump($list);
        $this->display();*/
	}

    /**
     * 添加奖项
     */
    public function add(){
        $periods=I("get.periods",1,'intval');
        $info=M('rose_prize')->where('periods='.$periods)->select();
        $this->assign('periods',$periods);
        $this->assign('info',$info);
        $this->display();
    }

    /**
     * 更新
     */
    public function update(){
        $periods=I("post.periods",1,'intval');
        $prize_name=I("post.prize_name",'','trim');
        $prize_money=I("post.prize_money");
        $prize_num=I("post.prize_num",0,'intval');
        $prize_rule=I("post.prize_rule");
         $len=count($prize_name);
        $data=array();
        for($i=0;$i<$len;$i++){
            if(!$prize_name[$i] || !$prize_money[$i] || !$prize_num[$i] ||  !$prize_rule[$i]){
                continue;
            }
            $data[$i]['prize_name']=$prize_name[$i];
            $data[$i]['prize_money']=$prize_money[$i];
            $data[$i]['prize_num']=$prize_num[$i];
            $data[$i]['prize_rule']=$prize_rule[$i];
            $data[$i]['periods']=$periods;
        }
        M('rose_prize')->where('periods='.$periods)->delete();
        if(M('rose_prize')->addAll($data)){
            $this->success('添加成功', U('Rose/index'));
        }else{
            $this->success('添加失败', U('Rose/index'));
        }
    }

}
